package com.uinnova.springboot.demo.mybatis;

import com.github.pagehelper.PageHelper;
import com.uinnova.springboot.demo.kit.Retkit;
import com.uinnova.springboot.demo.mapper.SysUserMapper;
import com.uinnova.springboot.demo.model.SysUser;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀钦
 * @date 2018-12-30-17:15
 */
@RestController
@Api
public class MybatisController {

    @Autowired
    private SysUserMapper sysUserMapper;

    @PostMapping(value = "/jail/mybatis/user")
    public Retkit<SysUser> mybatisUser(@RequestBody SysUser sysUser) {
        sysUserMapper.insert(sysUser);
        return Retkit.ok(sysUser);
    }

    @GetMapping(value = "/jail/mybatis/user/{id}/info")
    public List<SysUser> listSysUser(@PathVariable String id) {

        return sysUserMapper.listUserById(id);
    }

    @GetMapping(value = "/jail/mybatis/page/{pageNum}/{pageSize}")
    public List<SysUser> sysUserListPage(@PathVariable Integer pageNum,@PathVariable Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        return sysUserMapper.selectAll();
    }
}
